
#include "serialTreeSum.h"
#include "ttgTreeSum.h"
#include "tbbTreeSum.h"

int main()
{
	//Initing.
	ttg::services::ServiceBase::getRef()->start();
	tbb::task_scheduler_init init(tbb::task_scheduler_init::automatic);
	printf("TBB vs TTG: TreeSum\n");
	printf("CPU type: %s\n\n", ttg::services::CPUAnalyzer::getRef()->getCPUInfo());
	//Generating tree.
	printf("Creating test binary tree ...\n");
	BinaryTree<float> *tree = BinaryTree<float>::generate(10 * 1024 * 1024, -100.0f, 100.0f);
	//Serial sum.
	printf("Calculating using serial version ...\n");
	std::pair<float, double> serialSum = serialTreeSum(tree);
	printf("Elapsed %f seconds\n", serialSum.second);
	//ttg sum.
	printf("Calculating using ttg version ...\n");
	std::pair<float, double> ttgSum = ttgTreeSum(tree);
	printf("Elapsed %f seconds\n", ttgSum.second);
	if (!ttg::math::isEqualEps(serialSum.first, ttgSum.first, 0.01f))
		printf("Warning! Wrong results: serial == %f, ttg == %f\n", serialSum.first, ttgSum.first);
	//tbb sum.
	printf("Calculating using tbb version ...\n");
	std::pair<float, double> tbbSum = tbbTreeSum(tree);
	printf("Elapsed %f seconds\n", tbbSum.second);
	if (!ttg::math::isEqualEps(serialSum.first, tbbSum.first, 0.01f))
		printf("Warning! Wrong results: serial == %f, tbb == %f\n", serialSum.first, tbbSum.first);
	return 0;
}
